package com.lin.csdn.dao.impl;

import com.lin.csdn.dao.BaseDao;
import com.lin.csdn.model.po.Picture;

import java.util.ArrayList;
import java.util.List;

public class PicDao extends BaseDao {

    public void addPicUrl(int blogId,String path){
        List<Object> IList=new ArrayList<>();
        IList.add(path);
        IList.add(blogId);
        IList.add(0);
        IList.add(0);
        List<Object> UList=new ArrayList<>();
        UList.add(path);
        UList.add(blogId);
        List<Object> AList=new ArrayList<>();
        AList.add(blogId);
        Object target=findSingle("SELECT id FROM picture where blogid=?",AList);
        if(target!=null)
        update("UPDATE picture SET picurl=? WHERE blogid=?",UList);
        else
        update("INSERT INTO picture (picurl,blogid,reportid,shareid) VALUES (?,?,?,?)",IList);
    }

    public void addReportPic(int reportId,String path){
        List<Object> IList=new ArrayList<>();
        IList.add(path);
        IList.add(0);
        IList.add(reportId);
        IList.add(0);
        update("INSERT INTO picture (picurl,blogid,reportid,shareid) VALUES (?,?,?,?)",IList);
    }

    public String searchReportPic(int reportId){
        List<Object> list=new ArrayList<>();
        list.add(reportId);
        Class<Picture> cls=Picture.class;
        Object result=find("SELECT picurl FROM picture where reportid=?",list,cls);
        return String.valueOf(result);
    }

    public String searchSharePic(int shareId){
        List<Object> list=new ArrayList<>();
        list.add(shareId);
        Class<Picture> cls=Picture.class;
        Object result=find("SELECT picurl FROM picture where shareid=?",list,cls);
        return String.valueOf(result);
    }
}
